﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
namespace NFine.Util
{
    public class OperatorProvider
    {
        public static OperatorProvider Provider
        {
            get { return new OperatorProvider(); }
        }
        private string LoginUserKey = "nfine_login_user";

        public OperatorModel GetOperator()
        {
            string sessionString = StaticHttpContext.Current.Session.GetString(LoginUserKey);
            if (!string.IsNullOrEmpty(sessionString))
            {
                OperatorModel operatorModel = JsonConvert.DeserializeObject<OperatorModel>(sessionString);
                return operatorModel;
            }
            else
            {
                return null;
            }
        }
        public void AddOperator(OperatorModel operatorModel)
        {
            StaticHttpContext.Current.Session.SetString(LoginUserKey, JsonConvert.SerializeObject(operatorModel));
        }
        public void RemoveOperator()
        {
            StaticHttpContext.Current.Session.Remove(LoginUserKey);
        }
    }
}
